using _RobotInspection.DTO;
using _RobotInspection.Entities;
using _RobotInspection.Interfaces;
using _RobotInspection.Models;
using _RobotInspection.ReApiHelp;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Security;
using System.Threading.Tasks;

namespace _RobotInspection.Services
{
    
    /// <summary>
    /// 服务类
    /// </summary>
    public class Service : IService
    {
        private readonly ISqlSugarClient _db;

        public Service(ISqlSugarClient db)
        {
            _db = db;
        }
        
        public async Task<ActionResult<ApiResponse<object>>> UnitSelectAsync(string Unit)
        {
            // 添加业务逻辑验证
            if (string.IsNullOrWhiteSpace(Unit))
            {
                throw new BusinessException(400, "机组名称不能为空");
            }

            var result = await _db.Queryable<equipment>().Where(e => e.unit == Unit).ToListAsync();
            return new OkObjectResult(result);
        }

        public async Task<ActionResult<ApiResponse<object>>> EquipmentNameAsync(string Unit, string equipName)
        {
            // 添加业务逻辑验证
            if (string.IsNullOrWhiteSpace(Unit))
            {
                throw new BusinessException(400, "机组名称不能为空");
            }

            if (string.IsNullOrWhiteSpace(equipName))
            {
                throw new BusinessException(400, "设备名称不能为空");
            }

            var result = await _db.Queryable<equipment>().Where(e => e.unit == Unit && e.equipment_name == equipName).ToListAsync();
            return new OkObjectResult(result);
        }


        
    }
    
}